/*
 * Alex Veltsistas G00651470
 * Josh Hornsby G00721274
 * 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package proj3;

import java.io.BufferedReader;
import java.io.InputStream;

class ServerListenerThread extends Thread
{
    volatile boolean notFinished = true;
    public BufferedReader reader;
    private final InputStream input;
    public ServerListenerThread(InputStream input)
    {
        this.input = input;
    }
    public void stopThread()
    {
        notFinished = false;
    }
    @Override
    public void run() 
    {
        try
        {
            while(notFinished)
            {
                int available = input.available();
                if(available > 0)
                {
                    byte[] s = new byte[available];
                    input.read(s);
                    System.out.print(new String(s,"UTF-8"));
                }
                Thread.yield();
            }
        } 
        catch (Exception ex)
        {
            System.out.println("An error occured when reading from server!");
        }
    }
}